﻿using Sustainalytics.Entities;
using System;
using System.Collections.Generic;

namespace Sustainalytics.ClientDW.Entities
{
    public class GCOverallCompanySummary : IEqualityComparer<GCOverallCompanySummary>, IEntity, IHasUniverseIds
    {
        public Guid Id { get; set; }
        public List<int> UniverseIds { get; set; }
        public GCCompanyProfile CompanyProfile { get; set; }
        public DateTime? GCSignatorySince { get; set; }
        public GCAssessment OverallCompanyAssessment { get; set; }
        public DateTime OverallCompanyAssessmentEffectiveSince { get; set; }
        public DateTime LastUpdated { get; set; }
        public string ReasonForNonCompliance { get; set; }

        public void LoadFrom(GCOverallCompanySummary data)
        {
            this.Id = data.Id;
            this.CompanyProfile = data.CompanyProfile;
            this.GCSignatorySince = data.GCSignatorySince;
            this.OverallCompanyAssessment = data.OverallCompanyAssessment;
            this.OverallCompanyAssessmentEffectiveSince = data.OverallCompanyAssessmentEffectiveSince;
            this.LastUpdated = data.LastUpdated;
        }

        public bool Equals(GCOverallCompanySummary x, GCOverallCompanySummary y)
        {
            if (x == null && y == null)
                return true;

            if (x == null || y == null)
                return false;

            return
                x.Id == y.Id
                && new GCCompanyProfile().Equals(x.CompanyProfile, y.CompanyProfile)
                && ((x.GCSignatorySince == null && y.GCSignatorySince == null) || (x.GCSignatorySince.Value.Date == y.GCSignatorySince.Value.Date))
                && x.OverallCompanyAssessment == y.OverallCompanyAssessment
                && x.OverallCompanyAssessmentEffectiveSince.Date == y.OverallCompanyAssessmentEffectiveSince.Date
                && x.LastUpdated.Date == y.LastUpdated.Date;
        }

        public int GetHashCode(GCOverallCompanySummary obj)
        {
            return this.Id.GetHashCode();
        }
    }
}
